package com.sysfrog.cucumber;

/*
* Copyright (C) 2010 Thomas Heggelund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.SyntaxHighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import com.sysfrog.cucumber.lexer.CucumberLexer;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;
import static com.sysfrog.cucumber.lexer.CucumberTokenTypesNew.*;

public class CucumberSyntaxHighlighter extends SyntaxHighlighterBase {
    public static Map<IElementType, TextAttributesKey> keys;

    static {
        keys = new HashMap<IElementType, TextAttributesKey>();

        // Cucumber ting
        keys.put(FEATURE, createTextAttributesKey("CUCUMBER.FEATURE", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(GIVEN, createTextAttributesKey("CUCUMBER.GIVEN", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(WHEN, createTextAttributesKey("CUCUMBER.WHEN", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(THEN, createTextAttributesKey("CUCUMBER.THEN", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(AND, createTextAttributesKey("CUCUMBER.AND", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(I, createTextAttributesKey("CUCUMBER.I", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(IN, createTextAttributesKey("CUCUMBER.IN", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(AN, createTextAttributesKey("CUCUMBER.AN", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(ORDER, createTextAttributesKey("CUCUMBER.ORDER", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(WANT, createTextAttributesKey("CUCUMBER.WANT", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(SCENARIO, createTextAttributesKey("CUCUMBER.SCENARIO", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(OUTLINE, createTextAttributesKey("CUCUMBER.OUTLINE", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(AS, createTextAttributesKey("CUCUMBER.AS", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()));
        keys.put(LINE_COMMENT, createTextAttributesKey("CUCUMBER.LINE_COMMENT", SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes()));
        keys.put(TABLE_ROW_START, createTextAttributesKey("CUCUMBER.TABLE_ROW", SyntaxHighlighterColors.STRING.getDefaultAttributes()));
        keys.put(TABLE_CELL, createTextAttributesKey("CUCUMBER.TABLE_ROW", SyntaxHighlighterColors.STRING.getDefaultAttributes()));
        keys.put(BAD_CHARACTER, createTextAttributesKey("CUCUMBER.BAD_CHARACTER", HighlighterColors.BAD_CHARACTER.getDefaultAttributes()));
        keys.put(STRING_LITERAL, createTextAttributesKey("CUCUMBER.STRING_LITERAL", SyntaxHighlighterColors.STRING.getDefaultAttributes()));
        keys.put(TAG, createTextAttributesKey("CUCUMBER.TAG", SyntaxHighlighterColors.NUMBER.getDefaultAttributes()));
    }

    @NotNull
    public Lexer getHighlightingLexer() {
        return new CucumberLexer();
    }

    @NotNull
    public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
        return pack(keys.get(tokenType));
    }
}

